<?php

namespace app\controllers\admin;

use yii;
use app\commands\ErrorMsg;
use app\commands\Helper;
use app\commands\Validator;
use app\Services\admin\LoginService;
use yii\web\Controller;
use linslin\yii2\curl;


class LoginController extends Controller
{
    public $req = array();
    public $user = array();

    /**
     * 安全 校验 屏蔽
     * 预处理  权限等等操作处理
     */
    public function beforeAction($action){
        $this->req = Helper::in(array_merge($_POST, $_GET));
        return true;
    }

    /**
     * 登录
     *
     */
    public function actionLogin(){
        $req = $this->req;
        # 请求参数验证
        $rules = array(
            'username'  => "required",
            'password'  => "required"
        );
        Validator::validator($req, $rules,ErrorMsg::ERROR_MSG);
        $res = LoginService::getInstance()->login($req);
        Helper::right_out($req,$res);
    }

}
